<!DOCTYPE html>
<html lang="en">
    <head>
        <title>promise的all方法</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="css/style.css" rel="stylesheet">
    </head>
    <body>
    
    </body>
    <script>
    // promise.all() 将多个promsie实例合并成一个新实例
    // 只有所有的promise实例的状态都为fulfilled，最终结果才能执行.then
    // 如果有一个promise实例的状态为rejected，那么最终结果会执行.catch
    let promise1 = new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(1000)
        }, 1000)
    })

    let promise2 = new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve('hello')
        }, 1000)
    })

    let promise3 = new Promise((resolve, reject) => {
        setTimeout(() => {
            reject('promise3失败了')
        }, 1000)
    })

    let promise4 = Promise.all([promise1, promise2, promise3])
       .then((res) => {
            console.log(res);
        })
       .catch((err) => {
            console.log(err)
        })
</script>
</html>